- name: Create the directories to hold the templates
  file:
    path: "/root/ocp4/openshift-apps/{{project_name}}"
    state: directory
    owner: root
    group: root
    mode: 0770
    recurse: yes

# generate the templates for project to be created
- name: create the templates
  template:
    src: "{{ item }}"
    dest: "/root/ocp4/openshift-apps/{{project_name}}/{{ item }}"
    mode: 0770
  with_items: "{{ project_templates }}"

# apply created openshift resources
- name: oc apply resources
  command: "/root/bin/oc apply -f /root/ocp4/openshift-apps/{{project_name}}/{{ item }}"
  with_items: "{{ project_templates }}"

# create the service account
- name: create service account
  command: "/root/bin/oc create sa {{ project_service_account }} -n {{ project_name }}"
  register: sa_resource_create
  failed_when: sa_resource_create.stderr != '' and 'already exists' not in sa_resource_create.stderr
